<?php

namespace common\models\user;

use Yii;

/**
 * This is the model class for table "{{%user_signin_history}}".
 *
 * @property int $id
 * @property int $user_id
 * @property int $days 周期天数
 * @property int $sign_days 签到天数
 * @property string $first_date 当月首次签到日期
 * @property string $last_date 当月最后一次签到日期
 * @property int $history 当月签到历史
 * @property int $created_at
 * @property int $updated_at
 */
class UserSigninHistory extends \common\db\ActiveRecord {

    /**
     * {@inheritdoc}
     */
    public static function tableName() {
        return '{{%user_signin_history}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules() {
        return [
            [['user_id', 'days', 'sign_days', 'history', 'created_at', 'updated_at'], 'integer'],
            [['first_date', 'last_date'], 'required'],
            [['first_date', 'last_date'], 'date'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels() {
        return [
            'id' => 'ID',
            'user_id' => '用户UID',
            'days' => '周期天数',
            'sign_days' => '签到数',
            'first_date' => '周期内首次签到日期',
            'last_date' => '周期内最后一次签到日期',
            'history' => '签到历史',
            'created_at' => 'Created At',
            'updated_at' => 'Updated At',
        ];
    }

    public function getSignDates() {
        return \common\logics\base\SigninCalendarLogic::signedDates($this->first_date, $this->last_date, $this->history);
    }

}
